package com.ruoyi.points.pointsManage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.points.pointsManage.domain.Points;
import com.ruoyi.points.pointsManage.service.IPointsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 积分管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-07
 */
@Anonymous
@RestController
@RequestMapping("/points/pointsManage")
public class PointsController extends BaseController
{
    @Autowired
    private IPointsService pointsService;

    /**
     * 查询积分管理列表
     */
//    @PreAuthorize("@ss.hasPermi('points:pointsManage:list')")
    @GetMapping("/list")
    public TableDataInfo list(Points points)
    {
        System.out.println(points);
        startPage();
        List<Points> list = pointsService.selectPointsList(points);
        return getDataTable(list);
    }

    /**
     * 导出积分管理列表
     */
    @PreAuthorize("@ss.hasPermi('points:pointsManage:export')")
    @Log(title = "积分管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Points points)
    {
        List<Points> list = pointsService.selectPointsList(points);
        ExcelUtil<Points> util = new ExcelUtil<Points>(Points.class);
        util.exportExcel(response, list, "积分管理数据");
    }

    /**
     * 获取积分管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('points:pointsManage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pointsService.selectPointsById(id));
    }

    /**
     * 新增积分管理
     */
//    @PreAuthorize("@ss.hasPermi('points:pointsManage:add')")
    @Log(title = "积分管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Points points)
    {
        return toAjax(pointsService.insertPoints(points));
    }

    @Autowired
    ISysUserService sysUserService;

    // 根据用户账号添加新表
    @PostMapping("/addByUserName")
    public AjaxResult addByUserName(@RequestBody SysUser user)
    {
        SysUser sysUser = sysUserService.selectUserByUserName(user.getUserName());
        Points points = new Points();
        points.setUserId(sysUser.getUserId());
        points.setPoints(0);
        return toAjax(pointsService.insertPoints(points));
    }

    /**
     * 修改积分管理
     */
    @PreAuthorize("@ss.hasPermi('points:pointsManage:edit')")
    @Log(title = "积分管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Points points)
    {
        return toAjax(pointsService.updatePoints(points));
    }

    /**
     * 删除积分管理
     */
    @PreAuthorize("@ss.hasPermi('points:pointsManage:remove')")
    @Log(title = "积分管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pointsService.deletePointsByIds(ids));
    }
}
package com.ruoyi.points.pointsManage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.points.pointsManage.domain.Points;
import com.ruoyi.points.pointsManage.service.IPointsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 积分管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-07
 */
@RestController
@RequestMapping("/points/pointsManage")
public class PointsController extends BaseController
{
    @Autowired
    private IPointsService pointsService;

    /**
     * 查询积分管理列表
     */
//    @PreAuthorize("@ss.hasPermi('points:pointsManage:list')")
    @GetMapping("/list")
    public TableDataInfo list(Points points)
    {
        System.out.println(points);
        startPage();
        List<Points> list = pointsService.selectPointsList(points);
        return getDataTable(list);
    }

    /**
     * 导出积分管理列表
     */
    @PreAuthorize("@ss.hasPermi('points:pointsManage:export')")
    @Log(title = "积分管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Points points)
    {
        List<Points> list = pointsService.selectPointsList(points);
        ExcelUtil<Points> util = new ExcelUtil<Points>(Points.class);
        util.exportExcel(response, list, "积分管理数据");
    }

    /**
     * 获取积分管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('points:pointsManage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pointsService.selectPointsById(id));
    }

    /**
     * 新增积分管理
     */
//    @PreAuthorize("@ss.hasPermi('points:pointsManage:add')")
    @Log(title = "积分管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Points points)
    {
        return toAjax(pointsService.insertPoints(points));
    }

    @Autowired
    ISysUserService sysUserService;

    // 根据用户账号添加新表
    @PostMapping("/addByUserName")
    public AjaxResult addByUserName(@RequestBody SysUser user)
    {
        SysUser sysUser = sysUserService.selectUserByUserName(user.getUserName());
        Points points = new Points();
        points.setUserId(sysUser.getUserId());
        points.setPoints(0);
        return toAjax(pointsService.insertPoints(points));
    }

    /**
     * 修改积分管理
     */
    @PreAuthorize("@ss.hasPermi('points:pointsManage:edit')")
    @Log(title = "积分管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Points points)
    {
        return toAjax(pointsService.updatePoints(points));
    }

    /**
     * 删除积分管理
     */
    @PreAuthorize("@ss.hasPermi('points:pointsManage:remove')")
    @Log(title = "积分管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pointsService.deletePointsByIds(ids));
    }
}
